/*
 * Created on Feb 9, 2005
 */
package com.jds.architecture.utilities;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;


/**
 * Transform strategy object used to transform a <code>Calendar</code> instance
 * to an array of integers containing that <code>Calendar's</code> {year, month, date}.  
 * Date standard used by the array will use those defined by the <code>CalendarConstants</code>
 * class.
 * 
 * The overriden method <code>transform(Object target)</code> accepts a <code>Calendar</code>
 * or <code>Date</code> object representing the date to be transformed.  RuntimeExceptions will be 
 * thrown when any other argument is passed to the method.
 * 
 * Classes that implement the <code>TransformStrategy</code> interface should be 
 * passed to <code>Transformer</code> objects via their constructor or to the 
 * <code>Transformer.transform(TransformStrategy, Object)</code> method.
 * 
 * @author Eugene P. Lozada, Arthur D. Gerona
 * @see Transformer
 * @see TransformStrategy
 */
public class CalendarToIntArray implements TransformStrategy {
	
	/**
	 * Returns an equivalent integer array representation of argument
	 * <code>Calendar</code> instance
	 * 
	 * @param target <code>Calendar</code> instance to transform
	 * @return array of integers representing the Calendar [year, month, date]
	 *
	 */
	public Object transform(Object target) {
		int[] a = new int[3];
		if(target instanceof Calendar) {
		Calendar calendar = (Calendar)target;	
		
			a[0]=calendar.get(Calendar.YEAR);
			a[1]=calendar.get(Calendar.MONTH)  + 1;
			a[2]=calendar.get(Calendar.DAY_OF_MONTH);
			//	calendar.s
			return a;
 
		} else {
			Date date = (Date) target;
			
			a[0]=date.getYear() + 1900;
			a[1]=date.getMonth()  + 1;
			a[2]=date.getDate();
			
			return a;
		}
		
	}
}
